﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using MDT.LifeSewagePlatform.Entity;
using MDT.LifeSewagePlatform.IRepository;
using Microsoft.EntityFrameworkCore;

namespace MDT.LifeSewagePlatform.Repository
{
    public class PlaceDutyRepository:HandleBaseRepository<PlaceDutyEntity>,IPlaceDutyRepository
    {
        public PlaceDutyRepository( )
        { 
        
        }

        public IQueryable<PlaceDutyView> GetPlaceDutys(Expression<Func<PlaceDutyView,bool>> expression)
        {
            var query = from placeduty in _dbContext.PlaceDutys.AsNoTracking().Where(d => d.IsDelete == false)
                        join provience in _dbContext.Regions.AsNoTracking() on placeduty.ProvinceID equals provience.ID
                        join city in _dbContext.Regions.AsNoTracking() on placeduty.CityID equals city.ID
                        join area in _dbContext.Regions.AsNoTracking() on placeduty.AreaID equals area.ID
                        select new PlaceDutyView()
                        {
                            DutyName = placeduty.DutyName,
                            ID = placeduty.ID,
                            CityID = city.ID,
                            CityName = city.DisplayName,
                            ProvinceID = provience.ID,
                            ProvinceName = provience.DisplayName,
                            AreaID = area.ID,
                            AreaName = area.DisplayName,
                            PhoneNumber = placeduty.PhoneNumber,
                            Email = placeduty.Email,
                            NumPeople = placeduty.NumPeople
                        };
            return query.Where(expression);

        }
    }
}
